home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 098 / fidomail.dqc / fidomail.doc
Encoding:
Text File  |  1985-03-28  |  49.5 KB  |  1,484 lines

  1.         Fidonet Electronic Mail Protocol 8 Feb 85 Page 1
  2.  
  3.  
  4.                 
  5.                 Tom Jennings
  6.                 2269 Market Street #118
  7.                 San Francisco CA 94114
  8.  
  9.                 FidoNet Node #1
  10.                 415/864-1418
  11.  
  12.         INTENT
  13.  
  14.                 This document is an attempt to describe and define
  15.         the packet protocol used to support electronic mail under
  16.         the Fido/FidoNet system.
  17.  
  18.                 It will not describe or define Fido/Fidonet software
  19.         operation, nor even describe what the system does; for that,
  20.         I refer you to the following Fido manuals:
  21.  
  22.         Fido's Installation Manual      (INSTALL.DOC)
  23.         Fido's Operating Manual         (FIDO.DOC)
  24.         Fido's FidoNet Manual           (FIDONET.DOC)
  25.  
  26.                 Only the lower layers of the protocol will be
  27.         discussed here; routing, forwarding, dialing algorithms and
  28.         such will not be covered. These are mentioned, albeit
  29.         briefly, in Fido's FidoNet Manual.
  30.  
  31.         BACKGROUND
  32.  
  33.                 FidoNet was designed to be more or less portable
  34.         within the existing "public domain" software base, ie. any
  35.         system that can support binary transfers via XMODEM or it's
  36.         variants is in theory capable of supporting FidoNet. This
  37.         does not mean to imply that the current Fido/FidoNet
  38.         software will be/can be transported to machines not
  39.         currently supported; it means that no designed in
  40.         limitations were intended. 
  41.  
  42.                 This document merely covers the algorithms used, and
  43.         the problems encountered, in the automatic transfer of
  44.         packets and files used by the MSDOS Fido/FidoNet system.
  45.  
  46.         DESCRIPTION
  47.  
  48.                 FidoNet is a true electronic mail system supported
  49.         by the Fido Bulletin Board System software, under MSDOS
  50.         version 2. It's function is to transfer textual messages,
  51.         and binary files, between physically seperate computers on
  52.         an automatic, unattended basis.
  53.  
  54.         BASIC ASSUMPTIONS
  55.  
  56.                 The basic unit of data in FidoNet, like most MSDOS
  57.         and CPM software, is the byte, which here means 8 bits. All
  58.         data transfers assume the availability of an 8 bit byte
  59.         capable channel; 7 bit ASCII is not adequate. Parity, if
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.         Fidonet Electronic Mail Protocol 8 Feb 85 Page 2
  68.  
  69.         used, must be transparent to the software.
  70.  
  71.                 FidoNet is transaction oriented; a channel
  72.         (connection) is made, data transferred, the channel closed.
  73.         In all existing cases, this means a typical modem/phone line
  74.         connection; dial, connect, transfer, disconnect, though
  75.         anything that might be considered a "channel" will work.
  76.  
  77.                 The most basic design criteria for FidoNet is
  78.         extremely short channel connect times, since the usual
  79.         channel is a telephone line, where costs are accumulated on
  80.         a per minute basis. Lowest possible costs is the single most
  81.         important issue here. For this reason, all packets are
  82.         preassembled; no processing at all is done at packet
  83.         transfer time.
  84.  
  85.                 Due to the lack of real time operating systems,
  86.         FidoNet runs on an alternating basis with Fido. While Fido
  87.         is running, users enter messages, attach files and the like,
  88.         to be later processed by FidoNet. When FidoNet gains control
  89.         (at a predetermined time of day) it packetizes outgoing
  90.         messages, then makes attempts to send these packets, and may
  91.         receive packets from other nodes, all asynchronouously. When
  92.         FidoNet's time slot is over, it deletes any un-sent packets,
  93.         unpacks any packets that were received, and then passes
  94.         control back to Fido. Note that incoming packets are not
  95.         examined in any way until the FidoNet time slot is over.
  96.  
  97.                 A basic concept in FidoNet is the "node". A node is
  98.         any computer capable of sending or receiving FidoNet mail
  99.         packets. All discussions of packet transfers here will
  100.         assume point to point transfers.
  101.  
  102.                 As background information, it should be noted that
  103.         routing, forwarding, cost accounting, etc is done at a much
  104.         higher layer; routing, for instance is done even before
  105.         packets are created, and determines the destination node. It
  106.         has no effect on packet transfer.
  107.  
  108.         SOFTWARE ASSUMPTIONS
  109.  
  110.                 Fido/FidoNet is written in 'C' (Lattice flavor) and
  111.         makes use (of course) of C style structures and strings.
  112.         Luckily, these are quite simple. Here are the following
  113.         basic components used throughout FidoNet:
  114.  
  115.         CHARACTERS:
  116.                 An 8 bit byte. The usual micro type "character"; all
  117.         8 bits may be signifigant. Usually 128ASCII.
  118.  
  119.         STRING:
  120.                 A one dimension array of 8 bit characters,
  121.         terminated by a null. (hex 0) Some are of a fixed length; in
  122.         this case, signifigant text is left justified, followed by
  123.         the null, and the rest of the string is indeterminate. In
  124.         practice, FidoNet strings vary from very few characters up
  125.         to 4000 characters or so.
  126.  
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.         Fidonet Electronic Mail Protocol 8 Feb 85 Page 3
  134.  
  135.  
  136.         INTEGERS:
  137.                 All integer variables are 16 bits ('C' shorts)
  138.         unsigned, and are in Intel (big endian) format; least byte
  139.         first in the byte stream.
  140.  
  141.         LONGS:
  142.                 A long integer is 32 bits, in Intel format.
  143.  
  144.         WHAT A PACKET IS
  145.  
  146.                 A packet is a file that consists of a header, a
  147.         variable amount of variable size messages, and a trailer.
  148.         Each message within a packet has a header, and a single
  149.         string of plain text.
  150.  
  151.                 +---------------+
  152.                 |               |
  153.                 |               | Header
  154.                 |               |
  155.                 +---------------+
  156.                 |               | Message #1
  157.                 +---------------+
  158.                 |               |
  159.                 /               /
  160.                 /               /
  161.                 |               |
  162.                 +---------------+
  163.                 |               | Message #N
  164.                 +---------------+
  165.                 |               | Trailer
  166.                 +---------------+
  167.  
  168.  
  169.                 The header and trailer are of fixed length. All of
  170.         the messages are variable length, but have a fixed number of
  171.         fields within them.
  172.  
  173.                 Packets must be treated as a byte stream; for many
  174.         of the components, "type" flags determine the format of
  175.         upcoming data, therefore it is difficult to "read ahead",
  176.         except for buffering purposes.
  177.  
  178.         THE HEADER:
  179.  
  180.                 The header is a fixed length structure, and contains
  181.         the originating and destination nodes, the date the packet
  182.         was made, a version number, and some extra space for future
  183.         expansion.
  184.  
  185.                 Foolishly, there is no "type" identifier in the
  186.         packet header.
  187.  
  188.         A PACKET MESSAGE:
  189.  
  190.                 Each message contains an interger "type", followed
  191.         by the message fields. These are: attribute, originating
  192.  
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.         Fidonet Electronic Mail Protocol 8 Feb 85 Page 4
  200.  
  201.         node, destination node, two zeros, cost, date string, "to"
  202.         string, "from" string, "Subject" string, followed by the
  203.         text string.
  204.  
  205.                 The type, attribute, orig and dest node numbers, the
  206.         two zeros and cost are all integers. The other are serial
  207.         byte streams, strings, of variable length.
  208.  
  209.                                 INPORTANT NOTE:
  210.  
  211.                 Due to extreme shortsightedness in the original
  212.         packet design, the message type 1 did not include the
  213.         originating and destination node numbers; FidoNet inserted
  214.         the node numbers found in the packet header when the message
  215.         was unpacked and stored in the system.
  216.  
  217.                 Routing meant that messages for many different nodes
  218.         were packed into a single packet; needless to say this means
  219.         that the node numbers may not be the same for each message,
  220.         as was the previous assumtion.
  221.  
  222.                 A message type 2 (the one described above) was added
  223.         to accomodate the "extra" information. Starting in version
  224.         10, FidoNet will no longer create message type 1, though it
  225.         will continue to receive them. Other implementations may
  226.         ignore message type 1, and assume that all are message type
  227.         2.
  228.  
  229.         THE TRAILER:
  230.  
  231.                 The trailer consists of a single integer 0. This can
  232.         be thought of as a message type 0. This ends the packet; any
  233.         data following it (as when XMODEM rounds the packet up to
  234.         the next highest 128 bytes) should be ignored.
  235.  
  236.  
  237.         SYSTEM ASSUMPTIONS
  238.  
  239.                 Fido and FidoNet were designed using some basic
  240.         software building block concepts, admittedly stolen from
  241.         Ward Christensen's MODEM program. 
  242.  
  243.                 XMODEM with CRC error checking is used for the basic
  244.         mail packet transfer. No further discussion will be made as
  245.         to XMODEM implementation nor operation. Please refer to
  246.         other documents.
  247.  
  248.                 MODEM7, or more accurately, TELINK, protocol is used
  249.         to transfer any files "attached" after the message packet.
  250.         TELINK is identical to MODEM7, with the addition of an extra
  251.         data block, that passes MSDOS dependent file information
  252.         (time, date, exact file size) before the first data block.
  253.         FidoNet is still MODEM7 capable; all that is necessary is to
  254.         NAK the extra block, whose header character is ASCII SYN
  255.         instead of SOH when receiving from a TELINK based FidoNet.
  256.         For sending to TELINK based receiving FidoNets it is not
  257.         necessary to send this extra block. This protocol is also
  258.  
  259.  
  260.  
  261.  
  262.  
  263.  
  264.  
  265.         Fidonet Electronic Mail Protocol 8 Feb 85 Page 5
  266.  
  267.         described elsewhere.
  268.  
  269.  
  270.                 FidoNet assumes the presence of a clock of some
  271.         sort, for failsafe monitoring of packet transfers, and for
  272.         accounting purposes, to monitor actual connect times.
  273.         Accounting is outside the scope of this document.
  274.  
  275.                 A clock timer, preferably interrupt driven, is
  276.         needed to monitor the initial connection process, though may
  277.         be done using polled counters, if they are "calibrated".
  278.         This is fairly important; it prevents excessive connect
  279.         times if either the sender or receiver fails at any point.
  280.  
  281.  
  282.                 There are two basic subroutines used in the Fido
  283.         implementation of FidoNet. While these are very low level
  284.         hardware dependent routines, they are very important in
  285.         concept.
  286.  
  287.         DELAY ( N )
  288.  
  289.                 Delay for N centiseconds. This is just a time delay,
  290.         or time waster routine. It is used for generating time
  291.         delays for accomodating the telephone companies equipment.
  292.  
  293.         MODOUT ( CHARACTER )
  294.  
  295.                 Send a character to the modem. This is shown for
  296.         illustration purposes; it is used in the diagrams to follow.
  297.  
  298.         MODIN ( N )
  299.  
  300.                 Receive a character from the mode, but wait no
  301.         longer than N centiseconds. If a character is received, it
  302.         is returned; if it times out, -1 is returned. Since
  303.         characters are 8 bits, -1 (16 bits) indicates that no valid
  304.         character was received. This is a very basic, very important
  305.         function, upon which all of FidoNet is based.
  306.  
  307.                 The centisecond timer does not need to be accurate.
  308.         10% or less error is ideal, 20% is acceptable, and Fidonet
  309.         will usually still operate at up to 100% error. However,
  310.         repeatability will suffer, and sensitivity to the "length"
  311.         of a telephone connection will increase rapidly above 25%
  312.         error. 
  313.  
  314.                 This is implemented on MSDOS as an interrupt driver
  315.         timer; a polled timing loop is adequate if adjusted to match
  316.         the processor speed.
  317.  
  318.  
  319.  
  320.  
  321.  
  322.  
  323.  
  324.  
  325.  
  326.  
  327.  
  328.  
  329.  
  330.  
  331.         Fidonet Electronic Mail Protocol 8 Feb 85 Page 6
  332.  
  333.         PACKET TRANSFERS
  334.  
  335.                 Packet transfers will be described in two ways here;
  336.         first, a prose description, lacking exact details, and a
  337.         diagram with tables, with exact timing relationships and
  338.         values.
  339.  
  340.                 A FidoNet session consists of the following:
  341.  
  342.                 - Building routing tables
  343.  
  344.                 - Building list of active nodes
  345.  
  346.                 - Creating packets
  347.  
  348.                         - Compiling Messages
  349.  
  350.                         - Compiling list of attached files
  351.  
  352.                 - Sending/receiving Packets
  353.  
  354.                 - Deleteing outgoing packets, marking sent messages
  355.  
  356.                 - Unpacking incoming packets
  357.  
  358.                 - Return control to Fido
  359.  
  360.                 Only the creating of packets and attached file
  361.         lists, their transmission and reception, and unpacking is
  362.         covered here. The other steps are Fido dependent, and will
  363.         vary from implementation to implementation.
  364.  
  365.  
  366.         CREATING PACKETS:
  367.  
  368.                 FidoNet makes a number of passes through all of the
  369.         messages in the system. The first pass is merely to
  370.         determine which nodes have messages destined to them. Each
  371.         node is marked in a table, for later use in making packets
  372.         and dialing.
  373.  
  374.                 Additional passes are made, one for each node there
  375.         is mail to. A packet file is created on disk, using the
  376.         destination node number to create a unique filename (44.out
  377.         for a packet to node 44, etc), and the packet header is
  378.         written out.
  379.  
  380.                 When a message to this node is found, the message is
  381.         written out to the packet file. (The messages as stored in
  382.         Fido are described later in detail)
  383.  
  384.                 After the last message is written to the packet, the
  385.         trailer is written out, the file closed.
  386.  
  387.                 This process is repeated for all nodes that have
  388.         mail to be sent.
  389.  
  390.  
  391.  
  392.  
  393.  
  394.  
  395.  
  396.  
  397.         Fidonet Electronic Mail Protocol 8 Feb 85 Page 7
  398.  
  399.         SENDING PACKETS:
  400.         RECEIVING PACKETS:
  401.  
  402.                 FidoNet alternates sending and receiving packets for
  403.         most of the time slot. When it is not actually sending (or
  404.         attempting to send) a packet, it is waiting for one.
  405.  
  406.                 If there are no incoming calls, FidoNet makes
  407.         outgoing calls at a random one or two minute interval. A
  408.         node is chosen to call from the table compiled while making
  409.         packets. A node is picked sequentially from this table,
  410.         trying each one in sucession. When the end of the table is
  411.         reached, it starts over at the beginning.
  412.  
  413.                 When it is time to place a call, the next node is
  414.         chosen from the table, the telephone number is dialed. If no
  415.         connection is made, FidoNet goes back into receive mode. 
  416.  
  417.                 If a connection is made, CRs are sent, to determine
  418.         the baud rate. When the called system determines the baud
  419.         rate, it sends the "signon" message telling human callers it
  420.         is not available. This message is detected by the caller,
  421.         and terminates the baud detection. If baud is not detected
  422.         in 8 seconds, the caller disconnects.
  423.  
  424.                 The sender then waits for the line to clear (the
  425.         signon message to stop), then sends a character designated
  426.         as "TSYNC". This tells the receiver that it is a FidoNet
  427.         node calling, instead of a human caller. There is a 60
  428.         second limit placed on the TSYNC sequence. The receiver then
  429.         goes into XMODEM file receive, with a unique name for the
  430.         incoming packet. (0.in, 1.in ...) 
  431.  
  432.                 After sending TSYNC, the sender transmits the packet
  433.         (N.OUT) using normal XMODEM protocol.
  434.  
  435.                 After the packet is sent, the receiver goes
  436.         immediately into MODEM7 mode, to receive any attached files.
  437.  
  438.                 If there are no attached files, the sender sends an
  439.         EOT, which when received by the receiver in MODEM7, tells it
  440.         "no more files". If there are attached files, the sender
  441.         sends all of the files in the attached file list, using
  442.         MODEM7.
  443.  
  444.                 After either sending the attached files, or after
  445.         sending the EOT meaning no attached files, the sender delays
  446.         five seconds, then disconnects. After receiving the last
  447.         attached file (or the EOT) the receiver delays two seconds
  448.         and disconnects. The delay is to accomodate the telephone
  449.         systems peculiarity of keeping connect information on a
  450.         seperate, faster, channel that the data itself; without the
  451.         delay, it is possible for the "disconnect" to get there
  452.         before the character does.
  453.  
  454.                 If the packet was sent sucessfully, the sender
  455.         deletes the outgoing packet, the attached file list, and
  456.  
  457.  
  458.  
  459.  
  460.  
  461.  
  462.  
  463.         Fidonet Electronic Mail Protocol 8 Feb 85 Page 8
  464.  
  465.         marks the node table as "sucessful", and then returns to the
  466.         receive and wait mode.
  467.  
  468.         UNPACKING PACKETS:
  469.  
  470.                 When FidoNet mail time is over, any unsent outgoing
  471.         packets are deleted, and all messages that were sent
  472.         sucessfully are marked as SENT.
  473.  
  474.                 Each incoming packet (0.in, 1.in ...) is unpacked
  475.         and deleted. First, the destination node number is compared
  476.         to the nodes actual number. If it does not match (this
  477.         packet not really meant for this node) the packet is deleted
  478.         without further unpacking. If it matches, the messages are
  479.         unpacked and placed in the message area.
  480.  
  481.                 The packet is read as a byte stream, and interpreted
  482.         as read. When a message type is found, FidoNet assembles the
  483.         message as it goes.
  484.  
  485.                 Note that it is possible to receive part of a
  486.         packet; Fidonet will unpack all complete messages and store
  487.         them in the message area. It may find an error, such as an
  488.         incomplete packet. This is not a necessary feature; since
  489.         the packet was aborted, it will be sent again the next
  490.         night.
  491.  
  492.  
  493.  
  494.  
  495.  
  496.  
  497.  
  498.  
  499.  
  500.  
  501.  
  502.  
  503.  
  504.  
  505.  
  506.  
  507.  
  508.  
  509.  
  510.  
  511.  
  512.  
  513.  
  514.  
  515.  
  516.  
  517.  
  518.  
  519.  
  520.  
  521.  
  522.  
  523.  
  524.  
  525.  
  526.  
  527.  
  528.  
  529.         Fidonet Electronic Mail Protocol 8 Feb 85 Page 9
  530.  
  531.         FIDONET DIALING AND PACKET TRANSFER
  532.  
  533.                 This is the final, detailed, description of the
  534.         actual packet transfer. Some shorthand notation will be used
  535.         here; "clock" means a general purpose timer for monitoring
  536.         elapsed time, and is set and read during many parts of the
  537.         packet protocol. The two subroutines described above are
  538.         also used through out.
  539.  
  540.                 The descriptions her are in a C like "pseudo code",
  541.         for simplicity. Function or subroutine calls are shown as:
  542.  
  543.                 function(parameter);
  544.  
  545.                 Where function() is the subroutine, and "parameter"
  546.         is a parameter passed to the function. Parameters here may
  547.         be numeric values or strings, which can be determined from
  548.         context. Functions without parameters are shown as
  549.         function(). Functions may return a value, so that:
  550.  
  551.                 x= function()
  552.  
  553.                 Sets variable X to the value returned by function().
  554.  
  555.         IMPORTANT NOTE:
  556.  
  557.                 Ther is one extremely important construct that does
  558.         not, and cannot show up in these diagrams. This is a
  559.         mechanism to monitor Carrier Detect on the modem, and return
  560.         directly to a high level subroutine for error handling. This
  561.         is important due to the huge number of place where carrier
  562.         loss would have to be checked for, with the corresponding
  563.         high number of error return checks.
  564.  
  565.                 This can be implemented with a C like "set_jmp",
  566.         which stores the stack pointer and a return address, and
  567.         jumps to the return address if carrier is lost.
  568.  
  569.                 Also, in the Fido implementation, this error exit is
  570.         taken when the clock goes over the set limit. This frees the
  571.         high level code from having to watch the clock constantly.
  572.  
  573.                 The actual high level packet receive and send C
  574.         source is included at the end of this document to hopefully
  575.         make this a bit clearer.
  576.  
  577.  
  578.                 All mnemonics are standard ASCII control characters,
  579.         with the exception of "TSYNC", described below.
  580.  
  581.         Control Character Definitions
  582.  
  583.         Char    Hex     Dec
  584.         ----    ---     ---
  585.         CR      0d      13
  586.         EOT     04       4
  587.         TSYNC   ae     174
  588.  
  589.  
  590.  
  591.  
  592.  
  593.  
  594.  
  595.         Fidonet Electronic Mail Protocol 8 Feb 85 Page 10
  596.  
  597.  
  598.  
  599.         PACKET TRANSMISSION:
  600.  
  601.         send_packet:
  602.  
  603.         Attempt to place the call. If no connection, just return,
  604.         where FidoNet will wait for an incoming call, or delay one
  605.         or two minutes to place the next outgoing call.
  606.  
  607.                 set baud rate from node list
  608.                 dial phone number,
  609.                 if no connection, return
  610.  
  611.         A connection has been made. Determine the baud rate first.
  612.         This "whacks return" up to eight times; if no message
  613.         appears from whacking, it stops and calls it an error. The
  614.         "double whack" (sic) seems to work better than a single CR.
  615.         When the receiver determines the baud rate, it sends 4 CRs,
  616.         and the signon message, which also contains CRs. The sender
  617.         notices this and stops sending its CRs.
  618.  
  619.                 for (i= 1 to 8) {
  620.                         send CR, delay(20), send CR;
  621.                         if (modin(100) == CR) break out of loop;
  622.                 }
  623.  
  624.                 if (no CR received above) {
  625.                         mark table as one "connect",
  626.                         disconnect,
  627.                         return.
  628.                 }
  629.  
  630.         Baud rate is now detected. Set the failsafe timer, wait
  631.         until the line clears (the signon message stops coming),
  632.         then send TSYNC. If one minute elapses, disconnect and
  633.         return.
  634.  
  635.                 print ("Connected");
  636.  
  637.                 set clock to zero;
  638.                 while (clock is less than one minute) {
  639.                         if (modin(50) == -1) break out of loop;
  640.                 }
  641.                 if clock == one minute {
  642.                         disconnect,
  643.                         return.
  644.                 }
  645.  
  646.                 send (TSYNC);
  647.                 disable clock;
  648.                 print ("Sent TSYNC");
  649.  
  650.         Presumably, all connected now. Start sending the packet via
  651.         XMODEM. XMODEM will timeout after so many tries, so that
  652.         this will not hang if the other end fails or is not a
  653.         FidoNet.
  654.  
  655.  
  656.  
  657.  
  658.  
  659.  
  660.  
  661.         Fidonet Electronic Mail Protocol 8 Feb 85 Page 11
  662.  
  663.  
  664.                 print "Sending Packet"
  665.                 xmodem send (packet);
  666.  
  667.         Packet transmission complete. Mark the in memory table as
  668.         "succesful". If there are attached files, send them now,
  669.         otherwise just send an EOT.
  670.  
  671.                 success= 1;
  672.  
  673.                 if (attached files) 
  674.                         modem7 send attached files
  675.  
  676.                 else send EOT.
  677.  
  678.         All sent, delay 5 seconds to let things settle down.
  679.  
  680.                 delay(500)
  681.                 disconnect,
  682.                 return.
  683.  
  684.  
  685.  
  686.  
  687.  
  688.  
  689.  
  690.  
  691.  
  692.  
  693.  
  694.  
  695.  
  696.  
  697.  
  698.  
  699.  
  700.  
  701.  
  702.  
  703.  
  704.  
  705.  
  706.  
  707.  
  708.  
  709.  
  710.  
  711.  
  712.  
  713.  
  714.  
  715.  
  716.  
  717.  
  718.  
  719.  
  720.  
  721.  
  722.  
  723.  
  724.  
  725.  
  726.  
  727.         Fidonet Electronic Mail Protocol 8 Feb 85 Page 12
  728.  
  729.         PACKET RECEPTION:
  730.  
  731.         Carrier was detected while waiting to place a call or
  732.         waiting for an incoming call. Determine baud rate first,
  733.         display the signon message, then wait for TSYNC. There is a
  734.         one minute limit waiting for TSYNC. Note that connect()
  735.         watches the clock while waiting for CRs, and will take a
  736.         fatal error abort if it goes over the set limit. This
  737.         example therefore assumes that it will not timeout.
  738.  
  739.         receive_packet:
  740.  
  741.                 reset clock,
  742.                 connect()                       determine baud rate
  743.  
  744.                 print to modem:
  745.                         "FidoNet Version x.x
  746.                         FidoNet Node #N
  747.                         Processing mail Only"
  748.  
  749.                 while (clock less than one minute) {
  750.                         if modin(100) == TSYNC break out of loop;
  751.                 }
  752.  
  753.                 if (over one minute) {
  754.                         disconnect,
  755.                         return;
  756.                 }
  757.  
  758.         All connected, received TSYNC. Wait for the incoming packet.
  759.         Each incoming packet is named sequentially, starting at 0;
  760.         0.in, 1.in, 2.in, etc. If no packet was received, quite now;
  761.         no sense in trying to get attached files if no packet
  762.         received.
  763.  
  764.                 xmodem receive packet
  765.                 if no files received {
  766.                         disconnect,
  767.                         return.
  768.                 }
  769.  
  770.         Since it may have taken a few seconds to close up and write
  771.         out the packet file, the sender may have sent extra EOTs
  772.         from the end of the XMODEM packet transfer. Delay a bit, and
  773.         flush out the modem.
  774.  
  775.                 delay(200),
  776.                 flush modem,
  777.  
  778.         Now just go right into MODEM7 receive, for any attached
  779.         files. If there are none, the sender will send us an EOT,
  780.         which tells MODEM7 there are no more files. It can also just
  781.         hang up at this point, since the packet has already been
  782.         received. After the last, if any, file(s) received, delay 2
  783.         seconds and disconnect.
  784.  
  785.                 receive modem7 *.*
  786.  
  787.  
  788.  
  789.  
  790.  
  791.  
  792.  
  793.         Fidonet Electronic Mail Protocol 8 Feb 85 Page 13
  794.  
  795.                 delay(200),
  796.                 disconnect,
  797.                 return.
  798.  
  799.  
  800.  
  801.  
  802.  
  803.  
  804.  
  805.  
  806.  
  807.  
  808.  
  809.  
  810.  
  811.  
  812.  
  813.  
  814.  
  815.  
  816.  
  817.  
  818.  
  819.  
  820.  
  821.  
  822.  
  823.  
  824.  
  825.  
  826.  
  827.  
  828.  
  829.  
  830.  
  831.  
  832.  
  833.  
  834.  
  835.  
  836.  
  837.  
  838.  
  839.  
  840.  
  841.  
  842.  
  843.  
  844.  
  845.  
  846.  
  847.  
  848.  
  849.  
  850.  
  851.  
  852.  
  853.  
  854.  
  855.  
  856.  
  857.  
  858.  
  859.         Fidonet Electronic Mail Protocol 8 Feb 85 Page 14
  860.  
  861.         IMPLEMENTATION NOTES:
  862.  
  863.                 These are some suggestions on implementing FidoNet
  864.         on all systems. They are merely suggestions; obviously you
  865.         can do what you want.
  866.  
  867.  
  868.         LOW LEVEL FUNCTIONS:
  869.  
  870.                 As mentioned before, there are some low level
  871.         functions that at least some of which are probably
  872.         universal. The ideas below may make it easier to implement a
  873.         "bullet proof" FidoNet.
  874.  
  875.         ELAPSED TIME CLOCK:
  876.  
  877.                 This is a necessity, in one form or another. It's
  878.         accuracy does not need to be high. In Fido, it is
  879.         implemented as a timer tick interrupt, that increments in
  880.         memory variables: 'millisecs', 'seconds', 'minutes', and a
  881.         function to clear the clock, ie. set the above counters to
  882.         zero. (millisec is almost never actuall milliseconds; on the
  883.         IBM PC, for instance, the clock tick is at 55.55 mS; 55 is
  884.         added to 'millisec' every clock tick.)
  885.  
  886.                 There is an additional variable called 'limit', that
  887.         is the time limit to enforce for a particular routine.
  888.         Setting it to zero effectively disables the limit.
  889.  
  890.                 Thirdly, there is a function called limitchk(), that
  891.         does two things:
  892.  
  893.         1.      Watches the set time limit vs. the minute counter
  894.  
  895.         2.      Watches the carrier detect line from the modem
  896.  
  897.                 If either one of these events happens, it takes the
  898.         fatal error trap, and returns directly, instead of returning
  899.         normally.
  900.  
  901.  
  902.         limitchk() {
  903.  
  904.                 if (limit > 0) {
  905.                         if (minutes >= limit) frc_abort();
  906.                 }
  907.                 if ! dsr()) frc_abort();
  908.         }
  909.  
  910.                 frc_abort() is the fatal error jump, back to the
  911.         caller directly. dsr() is a function that returns false (0)
  912.         if carrier is lost. If no fatal errors, limitchk() just
  913.         returns.
  914.  
  915.  
  916.         MODIN(N)
  917.         MODOUT()
  918.  
  919.  
  920.  
  921.  
  922.  
  923.  
  924.  
  925.         Fidonet Electronic Mail Protocol 8 Feb 85 Page 15
  926.  
  927.  
  928.                 These two are the lowest level character IO in Fido.
  929.         modin(N) returns either a character from the modem, or -1
  930.         (TIMEOUT) if no character was available within N
  931.         centiseconds. This avoids hanging forever waiting for a
  932.         character that may never come.
  933.  
  934.                 modout() merely sends a character to the modem.
  935.  
  936.                 Both of these functions check for errors by calling
  937.         limitchk() while waiting for input or output ready.
  938.  
  939.         modin(n)
  940.         int n;
  941.         {
  942.                 millisec= 0L;
  943.                 while (millisec < (10 * n) ) {
  944.                         if (character ready) return(modem char);
  945.                         limitchk();
  946.                 }
  947.                 return(-1);
  948.         }
  949.  
  950.         modout(c)
  951.         char c;
  952.         {
  953.                 while (output not ready) {
  954.                         limitchk();
  955.                 }
  956.                 send char to modem
  957.         }
  958.  
  959.  
  960.  
  961.  
  962.  
  963.  
  964.  
  965.  
  966.  
  967.  
  968.  
  969.  
  970.  
  971.  
  972.  
  973.  
  974.  
  975.  
  976.  
  977.  
  978.  
  979.  
  980.  
  981.  
  982.  
  983.  
  984.  
  985.  
  986.  
  987.  
  988.  
  989.  
  990.  
  991.         Fidonet Electronic Mail Protocol 8 Feb 85 Page 16
  992.  
  993.         MESSAGES
  994.  
  995.                 While the message format is very Fido dependent, it
  996.         may be illustrative to show the correspondence between a
  997.         "normal" Fido message and one that has been installed in a
  998.         packet.
  999.  
  1000.                 This is the format of a Fido message, as contained
  1001.         in any Fido Message Area.
  1002.  
  1003.  
  1004.         /* Message header structure. The message text is just a long
  1005.         string. */
  1006.  
  1007.         struct _msg {
  1008.                 char from[36];          /* who from, */
  1009.                 char to[36];            /* who to, */
  1010.                 char subj[72];          /* message subject, */
  1011.                 char date[20];          /* creation date, */
  1012.                 int times;              /* number of times read, */
  1013.                 int dest;               /* destination node, */
  1014.                 int orig;               /* originating node */
  1015.                 int cost;               /* actual cost of msg */
  1016.                 int caca[6];            /* extra space, */
  1017.                 unsigned reply;         /* thread to previous */
  1018.                 int attr;               /* message type, */
  1019.                 int up;                 /* thread to next */
  1020.         };
  1021.  
  1022.         /* The message text starts at the byte following the end
  1023.         of the structure, and is terminated by a single null. */
  1024.  
  1025.         /* Bit values for msg.attr */
  1026.  
  1027.         #define MSGPRIVATE 1            /* private message, */
  1028.         #define MSGREAD 4               /* read by addressee */
  1029.         #define MSGSENT 8               /* sent OK (remote) */
  1030.         #define MSGFILE 16              /* file attached to msg */
  1031.         #define MSGFWD 32               /* being forwarded */
  1032.         #define MSGORPHAN 64            /* unknown dest node */
  1033.         #define MSGKILL 128             /* kill after mailing */
  1034.  
  1035.  
  1036.                 A Fido message is 191 bytes minimum; 190 bytes of
  1037.         header, above, and a variable amount of message text, null
  1038.         terminated. A fairly large klunky thing to pass around. When
  1039.         compacted into a packet, it is much smaller. As an example,
  1040.         assume the following message:
  1041.  
  1042.         From: Tom Jennings  On Fido 1
  1043.         To: John Madill  On Fido 2
  1044.         Subject: Test message
  1045.           This is text in the test message.
  1046.  
  1047.                 A hex dump of this test message follows. Note that
  1048.         the null terminated strings are followed by garbage; please
  1049.         ignore it.
  1050.  
  1051.  
  1052.  
  1053.  
  1054.  
  1055.  
  1056.  
  1057.         Fidonet Electronic Mail Protocol 8 Feb 85 Page 17
  1058.  
  1059.  
  1060.         54 6F 6D 20 4A 65 6E 6E-69 6E 67 73 00 00 8E 36   Tom Jennings...6
  1061.         00 00 00 FE FF 06 00 00-00 00 96 36 31 00 F3 21   ...~.......61.s!
  1062.         0A 00 00 00 4A 6F 68 6E-20 4D 61 64 69 6C 6C 00   ....John Madill.
  1063.         86 99 F8 27 86 99 02 28-00 00 91 36 57 61 69 74   ..x'...(...6Wait
  1064.         20 2E A0 99 AE 16 68 21-74 65 73 74 20 6D 65 73    . ...h!test mes
  1065.         73 61 67 65 00 00 65 00-FF 00 FC FF 00 00 B8 99   sage..e...|...8.
  1066.         40 00 AF 06 AF 06 65 06-40 00 65 00 65 00 FC FF   @././.e.@.e.e.|.
  1067.         00 00 AF 06 0D 06 40 00-65 00 FF 00 FC FF 00 00   ../...@.e...|...
  1068.         DA 99 65 00 AF 06 7E 60-1D 1A 83 F2 99 36 BC 27   Z.e./.~`...r.6<'
  1069.         32 33 20 4F 63 74 20 38-34 20 20 31 36 3A 31 39   23 Oct 84  16:19
  1070.         3A 34 38 00 01 00 02 00-01 00 1B 00 00 00 00 00   :48.............
  1071.         00 00 00 00 00 00 00 00-00 00 81 00 00 00 20 20   ..............  
  1072.         54 68 69 73 20 69 73 20-74 65 78 74 20 69 6E 20   This is text in 
  1073.         74 68 65 20 74 65 73 74-20 6D 65 73 73 61 67 65   the test message
  1074.         2E 0D 0A 0D 0A 00                                 ......          
  1075.  
  1076.                 When the message is packetized, it becomes much
  1077.         smaller; an entire packet, header, the above message and
  1078.         trailer, is only 164 bytes. The extra space and most of the
  1079.         Fido dependent items are removed.
  1080.  
  1081.         01 00 02 00 C0 07 09 00-02 00 10 00 19 00 0E 00   ....@...........
  1082.         00 00 01 00 00 00 00 00-00 00 00 00 00 00 00 00   ................
  1083.         00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00   ................
  1084.         00 00 00 00 00 00 00 00-00 00 01 00 01 00 1B 00   ................
  1085.         32 33 20 4F 63 74 20 38-34 20 20 31 36 3A 31 39   23 Oct 84  16:19
  1086.         3A 34 38 00 4A 6F 68 6E-20 4D 61 64 69 6C 6C 00   :48.John Madill.
  1087.         54 6F 6D 20 4A 65 6E 6E-69 6E 67 73 00 74 65 73   Tom Jennings.tes
  1088.         74 20 6D 65 73 73 61 67-65 00 20 20 54 68 69 73   t message.  This
  1089.         20 69 73 20 74 65 78 74-20 69 6E 20 74 68 65 20    is text in the 
  1090.         74 65 73 74 20 6D 65 73-73 61 67 65 2E 0D 0A 0D   test message....
  1091.         0A 00 00 00                                       ....
  1092.  
  1093.                 The packet header format is as follows. It is
  1094.         possible to follow, and hand disassemble, the message
  1095.         packet.
  1096.  
  1097.         struct _hdr {
  1098.                 int orig;               /* originating Node # */
  1099.                 int dest;               /* destination node */
  1100.                 int year,month,day,hour,minute,second;
  1101.                 int rate;               /* baud rate */
  1102.                 int ver;                /* packet version */
  1103.                 int extra[19];
  1104.         } pkthdr;
  1105.  
  1106.  
  1107.  
  1108.  
  1109.  
  1110.  
  1111.  
  1112.  
  1113.  
  1114.  
  1115.  
  1116.  
  1117.  
  1118.  
  1119.  
  1120.  
  1121.  
  1122.  
  1123.         Fidonet Electronic Mail Protocol 8 Feb 85 Page 18
  1124.  
  1125.         #include <stdio.h>
  1126.         #include <ctype.h>
  1127.         #include <bbs.h>
  1128.         #include <xfbuf.h>
  1129.         #include <ascii.h>
  1130.         #include <xtelink.h>
  1131.  
  1132.         #define TSYNC 0xae
  1133.  
  1134.         extern char ver[];
  1135.  
  1136.         extern unsigned crcmode;                /* 1 if CRC mode, */
  1137.         extern unsigned filemode;               /* transfer type; XMODEM, MODEM7, TELINK */
  1138.  
  1139.         /* Statistics on file transmission. */
  1140.  
  1141.         extern unsigned totl_files;             /* total files sent/rec'd */
  1142.         extern unsigned totl_failures;          /* how many failed, */
  1143.         extern unsigned totl_errors;            /* error count, soft errors incl */
  1144.         extern unsigned totl_blocks;            /* number blocks sent, */
  1145.  
  1146.         extern int minutes,seconds;
  1147.         extern int pktnum;                      /* incoming packet number */
  1148.  
  1149.         extern struct _route route[ROUTE_SIZE]; /* routing table */
  1150.         extern int maxnode;                     /* number of nodes in route table */
  1151.  
  1152.         extern struct _sched sched[SCHEDS];     /* scheduled events */
  1153.         extern char tag;                        /* handy local copy of the tag */
  1154.         extern int event;                       /* handy local copy of the current event */
  1155.  
  1156.         extern struct _nmap nmap[MAXNODES];     /* working node table */
  1157.         extern int nn;                          /* current node, */
  1158.         extern int nodetotal;                   /* number of nodes in the table */
  1159.  
  1160.         extern struct _pkthdr pkthdr;           /* FidoNet packet header */
  1161.         extern struct _mail mail;               /* MAIL.SYS */
  1162.         extern struct _node node;               /* in memory node descriptor */
  1163.         extern struct _sys sys;
  1164.  
  1165.         extern char *_txbuf;            /* message display buff, ASCII upload */
  1166.  
  1167.         extern int sysfiles;            /* total system files, */
  1168.  
  1169.         extern int overwrite;           /* 1 == allow overwriting files */
  1170.         extern int xferdisp;            /* 1 == display up/dn load status */
  1171.  
  1172.         extern int rate;                /* baud rate */
  1173.         extern int cd_flag;
  1174.         extern int limit;
  1175.  
  1176.         /* Carrier detected. Determine the baud rate, display a message to
  1177.         tell humans what were doing, then get in sync with the sender. Once
  1178.         in sync, receive the mail packet.
  1179.  
  1180.         The kludge 'state' tells us what point we reached, for logging. */
  1181.  
  1182.  
  1183.  
  1184.  
  1185.  
  1186.  
  1187.  
  1188.  
  1189.         Fidonet Electronic Mail Protocol 8 Feb 85 Page 19
  1190.  
  1191.         rcv_mail() {
  1192.  
  1193.         int i,n;
  1194.         char pktname[80],*cp;
  1195.         int msg_pkts,msg_blocks;
  1196.         int state;
  1197.  
  1198.                 gtod(pktname);
  1199.                 cprintf("\r\n * Incoming Call at %s\r\n",pktname);
  1200.                 lprintf("\r\n * Incoming Call at %s\r\n",pktname);
  1201.  
  1202.         /* We get an abort if: timeout, no sync (human caller), actual file transfer
  1203.         error, or packet received and sender hangs up. Totl_files is 0 if no
  1204.         packets transferred. */
  1205.  
  1206.                 totl_blocks= 0;
  1207.                 totl_files= 0;
  1208.                 msg_pkts= 0;
  1209.                 msg_blocks= 0;
  1210.                 clr_clk();                      /* reset the clock, */
  1211.                 limit= 1;                       /* limit to connect, */
  1212.                 cd_flag= 0;                     /* watch Carrier Detect */
  1213.                 state= 0;                       /* nothing yet */
  1214.  
  1215.                 set_abort(0);                   /* trap carrier loss here, */
  1216.                 if (was_abort()) {
  1217.                         if (state == 0) {
  1218.                                 cprintf(" * Never determined Baud Rate\r\n");
  1219.                                 lprintf(" * Never determined Baud Rate\r\n");
  1220.  
  1221.                         } else if (state == 1) {
  1222.                                 cprintf(" * Caller not a FidoNet\r\n");
  1223.                                 lprintf(" * Caller not a FidoNet\r\n");
  1224.  
  1225.                         } else if (msg_pkts == 0) {
  1226.                                 cprintf(" * Error during packet transfer\r\n");
  1227.                                 lprintf(" * Error during packet transfer\r\n");
  1228.  
  1229.                         } else {
  1230.                                 cprintf(" * Received packet\r\n");
  1231.                                 lprintf(" * Received packet\r\n");
  1232.                                 if (totl_files > 0) {
  1233.                                         lower_dtr();
  1234.                                         cprintf(" * Received %u files\r\n",totl_files);
  1235.                                         lprintf(" * Received %u files\r\n",totl_files);
  1236.                                         sprintf(pktname,"%u.fli",pktnum);
  1237.                                         i= _xcreate(pktname,2);
  1238.                                         if (i == -1) {
  1239.                                                 cprintf(" * Can't create %s\r\n",pktname);
  1240.                                                 lprintf(" * Can't create %s\r\n",pktname);
  1241.  
  1242.                                         } else {
  1243.                                                 _xwrite(i,_txbuf,strlen(_txbuf));
  1244.                                                 _xclose(i);
  1245.                                         }
  1246.                                         raise_dtr();
  1247.                                 }
  1248.  
  1249.  
  1250.  
  1251.  
  1252.  
  1253.  
  1254.  
  1255.         Fidonet Electronic Mail Protocol 8 Feb 85 Page 20
  1256.  
  1257.                         }
  1258.                         cd_flag= 0;                     /* real CD, */
  1259.                         if (cd()) discon();             /* hang up, delay for telco */
  1260.                         else delay(200);                /* delay for telco */
  1261.  
  1262.                         return(msg_pkts);
  1263.                 }
  1264.  
  1265.         /* The sender whacks CR until it gets a CR back. It then waits for the
  1266.         message to stop, sends a TSYNC, and starts the transfer. */
  1267.  
  1268.         /* -------------------- One Minute to Complete This ---------------------- */
  1269.  
  1270.         /* The CRs and message must be sent all at once; the receiver is looking
  1271.         for a quiet line, so any delays casued by logging, etc will foul things
  1272.         up. */
  1273.  
  1274.                 cprintf(" * Determining Baud Rate\r\n");
  1275.                 lprintf(" * Determining Baud Rate\r\n");
  1276.                 connect();
  1277.                 state= 1;                       /* DETERMINED BAUD RATE */
  1278.  
  1279.                 cprintf(" * FidoNet Signon Message\r\n");
  1280.                 for (i= 5; i--;) modout(CR);
  1281.                 sprintf(_txbuf,"   FidoNet Node #%u Version %s\r\n",mail.node,ver);
  1282.                 cp= _txbuf; while (*cp) modout(*cp++);
  1283.                 sprintf(_txbuf,"   Processing mail only, call back later.\r\n");
  1284.                 cp= _txbuf; while (*cp) modout(*cp++);
  1285.  
  1286.                 cprintf(" * Connected at %d baud, waiting for sync\r\n",rate);
  1287.                 lprintf(" * Connected at %d baud, waiting for sync\r\n",rate);
  1288.                 for (i= 30; i--;) {
  1289.                         n= modin(100);          /* 30 sec to get TSYNC */
  1290.                         if (n == TSYNC) break;
  1291.                         limitchk();             /* double check */
  1292.                 }
  1293.                 if (n != TSYNC) frc_abort();    /* no TSYNC */
  1294.                 state= 2;                       /* GOT TSYNC */
  1295.  
  1296.         /* ------------------- End One Minute to Complete -------------------- */
  1297.  
  1298.         /* All connected. Transfer the mail packet. No time limit, but the
  1299.         file receive will abort if there is an error. */
  1300.  
  1301.                 limit= 0;                       /* no time limit */
  1302.  
  1303.                 sprintf(pktname,"%u.in",++pktnum);      /* pick a new name, */
  1304.                 cprintf(" * Waiting for Mail Packet\r\n");
  1305.                 lprintf(" %s ",pktname);
  1306.  
  1307.                 crcmode= 1;                     /* CRC, */
  1308.                 filemode= XMODEM;               /* file xfer mode, */
  1309.                 *_txbuf= '\0';                  /* received file name */
  1310.                 recieve(pktname);               /* receive a packet, */
  1311.  
  1312.                 msg_pkts= totl_files;
  1313.                 msg_blocks= totl_blocks;        /* number of mail packets, */
  1314.  
  1315.  
  1316.  
  1317.  
  1318.  
  1319.  
  1320.  
  1321.         Fidonet Electronic Mail Protocol 8 Feb 85 Page 21
  1322.  
  1323.                 totl_files= 0;
  1324.                 totl_blocks= 0;
  1325.                 if (msg_pkts == 0) {            /* if nothing received */
  1326.                         frc_abort();            /* terminate here */
  1327.                 }
  1328.  
  1329.         /* Let extra EOTs, etc settle out, then flush it so the file receive
  1330.         doesnt get the extra EOTs. */
  1331.  
  1332.                 while (modin(10) != TIMEOUT);
  1333.  
  1334.         /* Wait for any incoming files. If there areent any, then the caller
  1335.         will just hang up if an older version, or will send EOT if no files. */
  1336.  
  1337.                 filemode= TELINK;
  1338.                 *_txbuf= '\0';                  /* get list of uploaded files */
  1339.                 recieve(mail.filepath);         /* get any files, */
  1340.                 delay(200);
  1341.                 frc_abort();                    /* error trap exit */
  1342.         }
  1343.  
  1344.         /* Send a mail packet to the remote. Dial the number, if error, return 0 to
  1345.         indicate no connection. Also, 'minutes' upon return reflects the actual
  1346.         connection time. */
  1347.  
  1348.         send_mail() {
  1349.  
  1350.         char pktname[80],floname[80];
  1351.         int n,f;
  1352.         int msg_pkts,msg_blocks;
  1353.         int state;
  1354.  
  1355.                 gtod(pktname);
  1356.                 cprintf("\r\n * Calling Fido%u %s %s at %s\r\n",node.number,node.name,node.phone,pktname);
  1357.                 lprintf("\r\n * Calling Fido%u %s %s at %s\r\n",node.number,node.name,node.phone,pktname);
  1358.  
  1359.                 sprintf(floname,"%u.flo",node.number);
  1360.                 *_txbuf= '\0';                  /* in case no file, */
  1361.                 f= _xopen(floname,0);           /* read in file list, */
  1362.                 if (f != -1) {
  1363.                         n= _xread(f,_txbuf,_TXSIZE);
  1364.                         _txbuf[n]= '\0';        /* null terminate it, */
  1365.                         _xclose(f);
  1366.                 }
  1367.  
  1368.                 sprintf(pktname,"%u.out",node.number);  /* local packet to send */
  1369.                 ++nmap[nn].tries;               /* log another try, */
  1370.  
  1371.         /* We get an abort if (1) it times out dialing, (2) we fail to connect 
  1372.         or (3) transmission sucessful, and receiver hung up. totl_files tells
  1373.         us what happened. */
  1374.  
  1375.                 totl_blocks= 0;
  1376.                 totl_files= 0;
  1377.                 msg_pkts= 0;
  1378.                 msg_blocks= 0;
  1379.                 state= 0;                       /* no connect yet */
  1380.  
  1381.  
  1382.  
  1383.  
  1384.  
  1385.  
  1386.  
  1387.         Fidonet Electronic Mail Protocol 8 Feb 85 Page 22
  1388.  
  1389.  
  1390.                 set_abort(0);
  1391.                 if (was_abort()) {
  1392.                         if (state > 0) {
  1393.                                 nmap[nn].time+= (minutes * 60) + seconds;
  1394.                                 ++nmap[nn].connects;
  1395.                         }
  1396.  
  1397.                         if (state == 0) {
  1398.                                 cprintf(" * No connection\r\n");
  1399.                                 lprintf(" * No connection\r\n");
  1400.  
  1401.                         } else if (state == 1) {
  1402.                                 cprintf(" * Disconnect before synchronization\r\n");
  1403.                                 lprintf(" * Disconnect before synchronization\r\n");
  1404.  
  1405.                         } else if (msg_pkts == 0) {
  1406.                                 cprintf(" * No packet(s) sent; probable non FidoNet system\r\n");
  1407.                                 lprintf(" * No packet(s) sent; probable non FidoNet system\r\n");
  1408.  
  1409.                         } else {
  1410.                                 cprintf(" * Sent %u packets %u files\r\n",msg_pkts,totl_files);
  1411.                                 lprintf(" * Sent %u packets %u files\r\n",msg_pkts,totl_files);
  1412.                                 nmap[nn].success= 1;
  1413.                                 _xdelete(pktname);      /* done with that packet */
  1414.                                 _xdelete(floname);
  1415.                         }
  1416.  
  1417.                         cd_flag= 0;
  1418.                         if (cd()) discon();
  1419.  
  1420.                         return(msg_pkts);
  1421.                 }
  1422.  
  1423.         /* Set the baud rate from the node list, and dial the number. Dialing is
  1424.         aborted if either a no-connect from the modem, or a timeout if no modem
  1425.         is connected. */
  1426.  
  1427.                 rate= 300;                              /* assume 300 baud, */
  1428.                 if (node.rate >= 1200) rate= 1200;      /* unless higher */
  1429.                 baud(rate);
  1430.                 cd_flag= 1;                             /* dont bomb on no carrier */
  1431.  
  1432.         /* -------------------- One Minute to Dial ---------------------- */
  1433.  
  1434.                 limit= 1;                               /* 1 min to dial, */
  1435.                 clr_clk();                              /* reset the clock, */
  1436.                 if (dial(node.phone) == 0) {
  1437.                         frc_abort();
  1438.                 }
  1439.  
  1440.                 rate= 300;                              /* again for stupid hardware */
  1441.                 if (node.rate >= 1200) rate= 1200;      /* that dials at fixed rates */
  1442.                 baud(rate);
  1443.                 cprintf(" * Connected at %d baud\r\n",rate);
  1444.                 lprintf(" * Connected at %d baud\r\n",rate);
  1445.                 state= 1;                               /* CONNECTION MADE */
  1446.  
  1447.  
  1448.  
  1449.  
  1450.  
  1451.  
  1452.  
  1453.         Fidonet Electronic Mail Protocol 8 Feb 85 Page 23
  1454.  
  1455.  
  1456.         /* -------------------- One Minute to Connect and Sync --------------- */
  1457.  
  1458.         /* Send CRs until we get a CR back, saying we detected baud correctly. */
  1459.  
  1460.                 clr_clk();                              /* reset clock, */
  1461.                 limit= 1;                               /* 1 min to connect, etc */
  1462.                 cd_flag= 0;                             /* now watch carrier */
  1463.  
  1464.                 delay(300);                             /* let modems settle */
  1465.                 mflush();                               /* flush buffers */
  1466.  
  1467.         /* Extremely noisy lines never settle (Fido 79), so just delay to
  1468.         let the modems connect, then flush the buffers of any garbage. 
  1469.  
  1470.                 while (modin(300) != TIMEOUT)           /* quiet line, */
  1471.                         limitchk();
  1472.         */
  1473.                 for (n= 10; --n;) {                     /* limited tries for baud test */
  1474.                         modout(CR);                     /* send CR CR until we */
  1475.                         delay(20);                      /* get one back, */
  1476.                         modout(CR);
  1477.                         if (modin(100) == CR) break;
  1478.                 }
  1479.                 if (n == 0) {
  1480.                         cprintf(" * No response to whacking CR\r\n");
  1481.                         lprintf(" * No response to whacking CR\r\n");
  1482.                         frc_abort();
  1483.                 }
  1484.